<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<link rel="stylesheet" type="text/css" href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
<style type="text/css">
li{list-style: none;}

</style>
</head>
<body class="gray-bg">
	<!-- 隐藏域 -->
	<input id="oldCarSeries" type="hidden" />

	<div class="container creditbody">
		 <div class="iboxtitle">
		 	<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;车辆信息修改</span>
         </div>
         <div class="buttonfixed" style="display: none;" id="buttons">
	       	<button type="button" id="save_button" class="btn dpbtn_blue" onclick="saveCarAction(false);">保存</button>
	       	<button type="button" id="commit_button" class="btn dpbtn_blue" onclick="saveCarAction(true);">提交</button>
	    </div>
	    <%@include file="/jsp/comm_yw_info_include_nohis.jsp"%>
         <div class="ibox-content ibox-con">
			<form class="form-horizontal buyinfor-form" id="commentForm">
				<div class="business-man">车辆信息</div>
	           	<div class="padding-nono">
			        <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
						<tr>	
							<td align="right">
								<label class="control-label np">车辆类别：</label>
							</td>
							<td>
								<mytag:selectTag id="categoryCar" name="categoryCar" map="${carCategory }"   others="class='select-control' required='required'"/>
							</td>
							
							<td align="right">
								<label class="control-label np">车辆颜色：</label>
							</td>
							<td>
								<mytag:selectTag id="colorCar" name="colorCar" map="${carColor }"   others="class='select-control' required='required'"/>
							</td>
							<td align="right">
								<label class="control-label np">新车指导价：</label>
							</td>
							<td>
								<input id="priceNewcar" placeholder="新车指导价" name="priceNewcar" class="form-control" readonly="readonly"  />
							</td>
						</tr>
						<tr>
							<td align="right"><label class="control-label np">车辆车型：</label>
							</td>
							<td colspan="3">
								<input type="text" placeholder="请输入汽车品牌(必填)" required="required" id="carName" class="form-control smalliconcur smallicon"
									name="carName" onclick="carcho(false,this.value);" /> 
								<input type="hidden" id="carModel" name="carModel" /> 
								<input id="carBrand" name="carBrand" type="hidden" /> 
								<input id="carSeries" name="carSeries" type="hidden" /> 
								<input type="hidden" id="nameCarModel" name="nameCarModel" /> 
								<input id="nameCarBrand" name="nameCarBrand" type="hidden" /> 
								<input id="nameCarSeries" name="nameCarSeries" type="hidden" />
								<input id="editCarId" name="editCarId" type="hidden"></td>
								<div id="seriesSelector" class="div_empNob"></div>
							</td>
							<td align="right">
								<label class="control-label np">合格证号：</label>
							</td>
							<td>
								<input id="numQualified" required="required" placeholder="合格证号(必填)" name="numQualified" class="form-control"   />
							</td>
						</tr>
						
						<tr>	
							<td align="right">
								<label class="control-label np">厂牌型号：</label>
							</td>
							<td>
								<input id="noticeModel" name="noticeModel" required="required" placeholder="厂牌型号(必填)" class="form-control"  />
							</td>
							
							<td align="right">
								<label class="control-label np">排量(L)：</label>
							</td>
							<td>
								<input id="displacement" name="displacement" required="required" placeholder="排量(必填)" class="form-control"  />
							</td>
							
							<td align="right">
								<label class="control-label np">功率：</label>
							</td>
							<td>
								<input id="power" name="power"  class="form-control" required="required" placeholder="功率(必填)"   />
							</td>
						</tr>
						<tr>	
							<td align="right">
								<label class="control-label np">发动机号：</label>
							</td>
							<td>
								<input id="numEngine" name="numEngine"  required="required" placeholder="发动机号(必填)"  class="form-control"    />
							</td>
							
							<td align="right">
								<label class="control-label np">底盘后6位：</label>
							</td>
							<td>
								<input id="numChassisSix" readonly="readonly" name="numChassisSix" class="form-control" type="text" maxlength="6" minlength="6" required="required" placeholder="底盘后6位(必填)"  />
							</td>
							<td align="right">
								<label class="control-label np">开票单位：</label>
							</td>
							<td>
								<input id="companyBill" name="companyBill" class="form-control" required="required" placeholder="开票单位(必填)"   />
							</td>
						</tr>
						<tr>	
							<td align="right">
								<label class="control-label np">发票日期：</label>
							</td>
							<td>
								<input id="dateBill" required="required" placeholder="发票日期(必填)" name="dateBill" class="smallicontm form-control" onclick="laydate({'time':false});" />
							</td>
							
							<td align="right">
								<label class="control-label np">发票号：</label>
							</td>
							<td>
								<input id="numBill" name="numBill" required="required" placeholder="发票号(必填)"  class="form-control"  />
							</td>
							<td align="right">
								<label class="control-label np">发票地区：</label>
							</td>
							<td>
								<input id="areaBill" name="areaBill" required="required" placeholder="发票地区(必填)" class="form-control"  />
							</td>
						</tr>
						<tr>	
							<td align="right">
								<label class="control-label np">车架号：</label>
							</td>
							<td>
								<input id="vin" required="required" placeholder="车架号(必填)" onblur="changenumEngine();" name="vin" class="form-control"/>
							</td>
						</tr>
					</table>
				</div>	
				<div class="business-manwife">备注信息</div>
				<div class="padding-nono">
		        	<table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
		        		<tr>
		        			<td align="right" valign="top">
								<label class="control-label np">备注信息：</label>
							</td>
							<td>
								<textarea id="remarks" name="remarks" required="required" placeholder="备注信息(必填)" class="form-control" cols="100"></textarea>
							</td>
		        		</tr>
		        	</table>
		        </div>			 
				<!-- 当前经办人 -->
	    		<%@include file="/jsp/comm_current_person_include.jsp"%>
			</form>
		</div>
	</div>	
	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>
	<%@include file="/jsp/carchoice_js_include.jsp"%>
	<%@include file="/jsp/comm_js_region_include_choice.jsp"%>
    <script type="text/javascript" src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
    <!--
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
	    jQuery(function($) {  
	    	getData();
	    	
	    	$("#commentForm").validate({
	            //重写showErrors
	            showErrors: function (errorMap, errorList) {
	                
	                $.each(errorList, function (i, v) {
	                    layer.tips(v.message, v.element, { time: 1500 });
	                    return false;
	                });  
	            },
	            /* 失去焦点时验证 */
	            onfocusout: function(element) { $(element).valid(); },
	            /*  键盘抬起不验证 */
	            onkeyup:false,
	        }); 
	    	
	    });
		
	    function changenumEngine(){
	    	var vin = $("#vin").val();
	    	var len = vin.length;
	    	var numChassisSix = vin.substring(len,len-6);
	    	$("#numChassisSix").val(numChassisSix)
	    }
	    
	 	function saveCarAction(commit){
	 		if(commit) {
	 			var validstatus = $("#commentForm").valid();
		    	if(!validstatus) {	    	
		    		layer.msg("有验证未通过，请仔细检查！", {icon: 5});
		    		return;
		    	}	
	 		}
			var data = {};
			var id = $('#editCarId').val();
			data.busiId = $("#busiId").val();
	 		data.cusId = $("#customerId").val();
	 		
	 		data.categoryCar = $('#categoryCar').val();
			data.colorCar = $('#colorCar').val();
			data.numQualified = $('#numQualified').val();
			data.noticeModel = $('#noticeModel').val();
			data.displacement = $('#displacement').val();
			data.power = $('#power').val();
			data.numEngine = $('#numEngine').val();
			data.numChassisSix = $('#numChassisSix').val();
			data.dateBill = $('#dateBill').val();
			data.companyBill = $('#companyBill').val();
			data.numBill = $('#numBill').val();
			data.areaBill = $('#areaBill').val();
			data.priceNewcar = $('#priceNewcar').val();
			data.vin = $('#vin').val();
			
			data.carBrand = $('#carBrand').val();
			data.nameCarBrand = $('#nameCarBrand').val();
			data.carSeries = $('#carSeries').val();
			data.nameCarSeries = $('#nameCarSeries').val();
			data.carModel = $('#carModel').val();
			data.nameCarModel = $('#nameCarModel').val();
			
			data.remarks = $('#remarks').val();
			
			data.commit = commit;
			var url = '';
			if(id && id != '') {
				data.id= id;
				url = '${basePath}/YwCarinfoEditController/modify';
			} else {
				url = '${basePath}/YwCarinfoEditController/save';
			}
			$.dpAjax({
 	    		url:url,
     			data:data,
     			success: function(datas){
     				$('#editCarId').val(datas.result.replaceId);
     				layer.msg('车辆修改信息保存成功', {icon: 6});
     				if(commit) {
     					var carSeries = $("#carSeries").val();
     					var oldCarSeries = $("#oldCarSeries").val();
     					if(carSeries != oldCarSeries){
     						layer.confirm('您已经更换了车型，如引发车价变化，请到修改贷款信息模块调整，操作人：<span style="color:#BD1723;">${current_user_key.uname}</span>', {
	       			  			  btn: ['确定','取消'] //按钮
	       					},function(){
	       						layer.closeAll();
	  	     					$('#buttons').hide();
	  	     					setTimeout(function(){
	  		     					location.href='${basePath}/web/system/yw/ywCarinfoEdit.jsp'; 
	  		     				 },3000);
	  	     				})
     					}else{
     						layer.confirm('您确认要提交信息吗？操作人：<span style="color:#BD1723;">${current_user_key.uname}</span>', {
	       			  			  btn: ['确定','取消'] //按钮
	       					},function(){
	       						layer.closeAll();
	  	     					$('#buttons').hide();
	  	     					setTimeout(function(){
	  		     					location.href='${basePath}/web/system/yw/ywCarinfoEdit.jsp'; 
	  		     				 },3000);
	  	     				})
     					}
     					
     				}
                 }
 	    	});
		}
	 	
	 	function getData() {
	 		var busiId = $('#busiId').val();
	 		if(busiId && busiId != '') {
		 		$.dpAjax({
		 			url:"${basePath}/YwCarinfoEditController/getChangedCarInfo",
		 			data:{busiId:busiId},
		 			success:function(datas){
		 				var data = datas.result;
		 				if(data && data != '') {
		 					var carinfoEditStatus = data.carinfoEditStatus;
		 					if(!carinfoEditStatus || carinfoEditStatus == '' || carinfoEditStatus == '10') {
		 						$('#buttons').show();
		 					} else {
		 						$('#buttons').hide();
		 					}
		 					$('#editCarId').val(data.replaceId);
		 					$('#categoryCar').val(data.categoryCar);
		 					$('#colorCar').val(data.colorCar);
		 					$('#numQualified').val(data.numQualified);
		 					$('#noticeModel').val(data.noticeModel);
		 					$('#displacement').val(data.displacement);
		 					$('#power').val(data.power);
		 					$('#numEngine').val(data.numEngine);
		 					$('#numChassisSix').val(data.numChassisSix);
		 					var dateBill = data.dateBill;
		 					dateBill = ((dateBill && dateBill != '') ? formateDate(dateBill) : '');
		 					$('#dateBill').val(dateBill);
		 					$('#companyBill').val(data.companyBill);
		 					$('#numBill').val(data.numBill);
		 					$('#areaBill').val(data.areaBill);
		 					$('#vin').val(data.vin);
		 					
		 					$('#carName').val(data.nameCarModel);
		 					$('#carBrand').val(data.carBrand);
		 					$('#nameCarBrand').val(data.nameCarBrand);
		 					$('#carSeries').val(data.carSeries);
		 					$('#nameCarSeries').val(data.nameCarSeries);
		 					$('#carModel').val(data.carModel);
		 					$('#nameCarModel').val(data.nameCarModel);
		 					$('#priceNewcar').val(data.priceNewcar);
		 					$("#oldCarSeries").val(data.carSeries)
		 					
		 					var remarks = data.remarks;
					 		var remarks =  (data.remarks).replace(/<\/?.+?>/g,"");
					 		var ddsremarks = remarks.replace(/&nbsp;/g,""); 
		 					$('#remarks').val(ddsremarks);
		 				}
		 			}
		 		});
	 		} else {
	 			console.log("busiId is empty! check it.");
	 		}
	 	}
	 	
    </script>
</body>
</html>
